package lcr;

public class Test0034 {
}

class Solution0034_1 {
    public boolean isAlienSorted(String[] words, String order) {
        int[] record = new int[26];
        for (int i = 0; i < order.length(); i++)
            record[order.charAt(i) - 'a'] = i;
        for (int i = 0; i < words.length-1; i++) {
            String w1 = words[i], w2 = words[i + 1];
            int minLength = Math.min(w1.length(), w2.length());
            for (int j = 0; j < minLength; j++) {
                if (w1.charAt(j) != w2.charAt(j)) {
                    if (record[w1.charAt(j) - 'a'] > record[w2.charAt(j) - 'a'])
                        return false;
                    break;
                } else if (j == minLength - 1&&w1.length() > w2.length()) {
                    return false;
                }
            }
        }
        return true;
    }
}
